package com.lvyq.javaprint.common;

import java.io.Serializable;

/**
 * @author lvyq 返回基类
 * @version 1.0
 * Create by 2024-05-06 9:38
 */
public class CommonResult<T> implements Serializable {

    /**
     * 状态码
     */
    private Integer code;

    /**
     * 提示信息
     * @see
     */
    private String msg;

    /**
     * 数据
     *
     */
    private T data;

    public static  <T>CommonResult error(ResultCode errorCode) {
        CommonResult result = new CommonResult();
        result.code=errorCode.getCode();
        result.msg=errorCode.getMsg();
        return result;
    }

    public static <T>CommonResult error() {
        CommonResult result = new CommonResult();
        result.code=GlobalCode.ERROR.getCode();
        result.msg=GlobalCode.ERROR.getMsg();
        return result;
    }
    public static <T> CommonResult success() {
        CommonResult result = new CommonResult();
        result.code=GlobalCode.SUCCESS.getCode();
        result.msg=GlobalCode.SUCCESS.getMsg();
        return result;
    }

    public static <T> CommonResult success(T data) {
        CommonResult result = new CommonResult();
        result.code=GlobalCode.SUCCESS.getCode();
        result.msg=GlobalCode.SUCCESS.getMsg();
        result.data = data;
        return result;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}
